package com.liuxvru.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuxvru.common.constant.SprintConstants;
import com.liuxvru.common.utils.SecurityUtils;
import com.liuxvru.project.domain.Sprint;
import com.liuxvru.project.mapper.SprintMapper;
import com.liuxvru.project.service.ISprintService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * SprintService业务层处理
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@Service
public class SprintServiceImpl extends ServiceImpl<SprintMapper, Sprint> implements ISprintService {


    /**
     * 查询Sprint列表
     *
     * @param sprint Sprint
     * @return Sprint
     */
    @Override
    public List<Sprint> selectSprintList(Sprint sprint) {
        return baseMapper.selectSprintList(sprint);
    }

    @Override
    public int add(Long projectId, Sprint sprint) {
        final Long userId = SecurityUtils.getUserId();
        sprint.setUpdatedBy(userId);
        sprint.setCreatedBy(userId);
        sprint.setProjectId(projectId);
        sprint.setStatus(SprintConstants.NOT_STARTED);
        return baseMapper.insert(sprint);
    }

    @Override
    public List<Sprint> getNoReleaseSprint(Long releaseId) {
        return baseMapper.selectList(new LambdaQueryWrapper<Sprint>().eq(Sprint::getProjectId, releaseId).isNull(Sprint::getReleaseId));
    }

}
